package com.taobao.livis.core;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.taobao.common.searchengine.SearchResult;
import com.taobao.item.constant.ItemOptionsConstants;
import com.taobao.item.domain.ItemDO;
import com.taobao.item.domain.result.ItemResultDO;
import com.taobao.item.exception.IcException;
import com.taobao.item.search.iteminstant.ItemInstantSimpleQuery;
import com.taobao.item.service.impl.ItemTairCacheBetaParam;
import com.taobao.livis.QueryItemTest;
import com.taobao.livis.util.LivisUtil;

public class MainStart {
//"spirng-icsample-hsf.xml", 
	public static void main(String[] args) throws IcException {
		String[] configLocation = { "spirng-icsample-core.xml","spirng-icsample-hsf.xml","spirng-icsample-iss.xml"};
		ApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
		QueryItemTest q = (QueryItemTest) context.getBean("queryItemTest");
		search(q);
		//checkItemBycache(q);
	}

	private static void checkItemBycache(QueryItemTest q) {
		try {
			ItemDO item = q.getItemById(1500005176445L);
			System.out.println(item);
			ItemTairCacheBetaParam.disableItemTairCache = false;
			ItemResultDO res = q.getClient().queryItemByIdWithCache(
					1500005176445L, null, LivisUtil.getApp("query"));
			System.out.println(res.getItem());
			q.getClient().queryItemForDetail(1500005176445L);
			int size = res.getItem().getItemProperties().size();
			for (int i = 0; i < size; i++) {
				String a = res.getItem().getItemProperties().get(i)
						.getValueAliasText();
				System.out.println(a);
			}
			System.out.println(q.getItemTairCacheService()
					.getItemDO(1500005176445L).getItemProperties().get(0)
					.getValueAliasText());
			System.exit(0);
		} catch (IcException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void search(QueryItemTest q) {
		ItemInstantSimpleQuery query = new ItemInstantSimpleQuery();
		query.setUserId(65753805);
		//不打折
		query.setDiscount(false);
		//打折
		//query.addOptionsBitIsOne(ItemOptionsConstants.ITEM_OPTIONS_PROMOTED);
		//不打折
		//query.addOptionsBitIsZero(ItemOptionsConstants.ITEM_OPTIONS_PROMOTED);
		//query.addOptionsBitIsZero(70368744177664L);
		SearchResult sr = q.searchItemByIss(query);
		System.out.println(sr.getAllNum());
		System.out.println(sr.getResultList().size());
	}
}
